package main.leetcode.offer.secondround.from03to50;

/** 11.旋转数组的最小数字 */
public class ex11 {
    public static void main(String[] args) {
        System.out.println(new ex11().minArray(new int[] {3, 4, 5, 1, 2}));
        System.out.println(new ex11().minArray(new int[] {2, 2, 2, 0, 1}));
        System.out.println(new ex11().minArray(new int[] {1, 3, 3}));
    }

    public int minArray(int[] numbers) {
        int l = 0, r = numbers.length - 1;
        while (l < r) {
            int mid = l + (r - l >>> 1);
            if (numbers[mid] < numbers[r]) {
                r = mid;
            } else if (numbers[mid] > numbers[r]) {
                l = mid + 1;
            } else {
                --r;
            }
        }
        return numbers[l];
    }
}
